package com.zhou.jiancai.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.mcxtzhang.captchalib.SwipeCaptchaView;
import com.zhou.jiancai.R;
import com.zhou.jiancai.base.BaseActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/4/12.
 */

public class SplashActivity extends BaseActivity {
    private static final int MSG_VISIBLE = 1;
    private static final int MSG_ERROR = 2;
    private static final String TAG = "SplashActivity";
    @InjectView(R.id.swipeCaptchaView)
    SwipeCaptchaView swipeCaptchaView;
    @InjectView(R.id.dragBar)
    SeekBar dragBar;
    @InjectView(R.id.button)
    Button button;
    @InjectView(R.id.button2)
    Button button2;
    @InjectView(R.id.button3)
    Button button3;
    private Response response;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MSG_VISIBLE:


                    break;
                case MSG_ERROR:

                    break;
                default:


            }

        }
    };


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.activity_splash);
        ButterKnife.inject(this);

        swipeCaptchaView.createCaptcha();
        Glide.with(SplashActivity.this)
                .load(R.mipmap.fengjing)
                .asBitmap()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        swipeCaptchaView.setImageBitmap(resource);
                        // swipeCaptchaView.createCaptcha();
                    }
                });

        //下载图片

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });

        dragBar.setEnabled(true);
        dragBar.setProgress(0);
        //重新设置
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                swipeCaptchaView.createCaptcha();//创建二维码图
                dragBar.setEnabled(true);//拖拽的bar
                dragBar.setProgress(0);
            }
        });

        //设置验证码比较的回调
        swipeCaptchaView.setOnCaptchaMatchCallback(new SwipeCaptchaView.OnCaptchaMatchCallback() {
            @Override
            public void matchSuccess(SwipeCaptchaView swipeCaptchaView) {
                Toast.makeText(SplashActivity.this, "恭喜你啊 验证成功 可以搞事情了", Toast.LENGTH_SHORT).show();
                //swipeCaptcha.createCaptcha();
                dragBar.setEnabled(false);
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }

            @Override
            public void matchFailed(SwipeCaptchaView swipeCaptchaView) {
                Log.d("zxt", "matchFailed() called with: swipeCaptchaView = [" + swipeCaptchaView + "]");
                Toast.makeText(SplashActivity.this, "你有80%的可能是机器人，现在走还来得及", Toast.LENGTH_SHORT).show();
                swipeCaptchaView.resetCaptcha();
                dragBar.setProgress(0);
            }
        });
        dragBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                swipeCaptchaView.setCurrentSwipeValue(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                //随便放这里是因为控件
                dragBar.setMax(swipeCaptchaView.getMaxSwipeValue());
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                Log.d("zxt", "onStopTrackingTouch() called with: seekBar = [" + seekBar + "]");
                swipeCaptchaView.matchCaptcha();
            }
        });

        //测试从网络加载图片是否ok   http://wx1.sinaimg.cn/mw1024/0069SjSogy1fehmrde5kij30k00zkmyt.jpg  我的

        //


    }

    @Override
    protected void initdata() {

    }

    @Override
    protected void initview() {

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_splash;
    }
}


